import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_shop/routes/application.dart';

class RecommendGoods extends StatelessWidget {
  final List recommendGoods;
  const RecommendGoods({ Key key, this.recommendGoods }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(top: 10.0),
      height: ScreenUtil().setHeight(426.0),
      child: Column(
        children: <Widget>[
          TitleWidget(title: '商品推荐'),
          RecommendWidget(recommendGoods: recommendGoods)
        ]
      ),
    );
  }
}

class TitleWidget extends StatelessWidget {
  final String title;
  const TitleWidget({ Key key, this.title }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      alignment: Alignment.centerLeft,
      padding: EdgeInsets.fromLTRB(ScreenUtil().setWidth(20.0), 2.0, 0.0, ScreenUtil().setHeight(20.0)),
      decoration: BoxDecoration(
        color: Colors.white,
        border: Border(
          bottom: BorderSide(width: 0.5,color: Colors.black26)
        )
      ),
      child: Text(title, style: TextStyle(color: Colors.pink)),
    );
  }
}

class RecommendWidget extends StatelessWidget {
  final List recommendGoods;
  const RecommendWidget({ Key key, this.recommendGoods }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      height: ScreenUtil().setHeight(360),
      padding: EdgeInsets.symmetric(horizontal: ScreenUtil().setWidth(20)),
      child: ListView.builder(
        scrollDirection: Axis.horizontal,
        itemCount: recommendGoods.length,
        itemBuilder: (context, index) {
          return RecommendItem(index: index, recommendGoods: recommendGoods);
        }
      ),
    );
  }
}

class RecommendItem extends StatelessWidget {
  final int index;
  final List recommendGoods;
  const RecommendItem({ Key key, this.index, this.recommendGoods }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    var Item = recommendGoods[index];
    return InkWell(
      onTap: () {
        Application.router.navigateTo(context, '/detail?id=123456');
      },
      child: Container(
        height: ScreenUtil().setHeight(360),
        width: ScreenUtil().setWidth(250),
        // padding: EdgeInsets.all(8.0),
        decoration: BoxDecoration(
          color: Colors.white,
          border: Border(
            left: BorderSide(width: 0.5, color: Colors.black26)
          )
        ),
        child: Column(
          children: <Widget>[
            Container(
              height: ScreenUtil().setWidth(250),
              width: ScreenUtil().setWidth(237),
              child: Image.network(Item['imgUrl'])
            ),
            Text('￥${Item['originPrice']}'),
            Text(
              '￥${Item['minPrice']}',
              style: TextStyle(
                decoration: TextDecoration.lineThrough,
                color: Colors.grey
              ),
            ),
          ],
        ),
      ),
    );
  }
}